package com.accelstack.cmp.service;

import com.accelstack.cmp.entity.Container;
import com.accelstack.cmp.enums.ContainerStatus;
import com.accelstack.cmp.repository.ContainerRepository;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Optional;

/**
 * 容器Service
 */
@Service
@RequiredArgsConstructor
@Transactional(readOnly = true)
public class ContainerService {
    
    private final ContainerRepository containerRepository;
    
    @Transactional
    public Container create(Container container) {
        return containerRepository.save(container);
    }
    
    @Transactional
    public Container update(Container container) {
        return containerRepository.save(container);
    }
    
    @Transactional
    public void deleteById(Long id) {
        containerRepository.deleteById(id);
    }
    
    public Optional<Container> findById(Long id) {
        return containerRepository.findById(id);
    }
    
    public List<Container> findAll() {
        return containerRepository.findAll();
    }
    
    public Page<Container> findAll(Pageable pageable) {
        return containerRepository.findAll(pageable);
    }
    
    public List<Container> findByVirtHostId(Long virtHostId) {
        return containerRepository.findByVirtHostId(virtHostId);
    }
    
    public List<Container> findByStatus(ContainerStatus status) {
        return containerRepository.findByStatus(status);
    }
}

